<template>
  <view class="container">
    <!-- 店铺展示部分 -->
	<swiper 
	  class="shop-swiper"
	  :autoplay="true" 
	  :interval="3000"
	  indicator-dots
	  indicator-color="rgba(255,255,255,0.5)"
	  indicator-active-color="#ffffff"
	  circular>
	  <swiper-item 
	    v-for="(item, index) in shopImg" 
	    :key="index">
	    <image 
	      :src="item" 
	      mode="widthFix" 
	      class="swiper-image"/>
	  </swiper-item>
	</swiper>
	
    <view class="shop-show">
      <view class="shop-info">
        <view class="shop-name">{{ shopInfo.shopName }}</view>
        <view class="shop-rating">
			<uni-rate size="18" :readonly="true" :value="3" />
          <text class="shop-score">{{ shopScore }}</text>
          <text class="sales">{{ '销量：' + sales }}</text>
        </view>
        
        <view class="business-time">{{ shopInfo.businessHours }}</view>
		门店详细地址:<view class="shop-address">{{ shopInfo.detailedAddress }}</view>
      </view>
    </view>
    <!-- 服务部分 -->
    <view class="service-section">
      <view class="section-title">服务</view>
      <view class="service-item" v-for="(service, index) in services" :key="index">
        <view class="service-checkbox">
          <!-- 使用uni-checkbox组件 -->
          <uni-checkbox v-model="service.checked"></uni-checkbox>
        </view>
        <view class="service-content">
          <view class="service-name">{{ service.name }}</view>
          <view class="service-price">
            <text class="old-price" v-if="service.oldPrice">{{ '￥' + service.oldPrice }}</text>
            <text class="new-price">￥{{ service.newPrice }}</text>
          </view>
        </view>
      </view>
    </view>
    <!-- 评价部分 -->
    <view class="evaluation-section">
      <view class="section-title">服务评价</view>
	  
      <view class="evaluation-item" v-for="(evaluation, index) in reviewInfo" :key="index">
        <view class="user-info">
          <image :src="evaluation.userAvatar" mode="widthFix" class="user-avatar"></image>
          <text class="user-name">{{ evaluation.userId }}</text>
          <text class="evaluation-time">{{ evaluation.createdAt }}</text>
        </view>
		<view class="rating">
			<view class="rating-box">
					<uni-rate :readonly="true" :value="evaluation.rating" :size="14" />
			</view>
		</view>
		<view class="content">
			<view>{{evaluation.content}}</view>
			
		</view>
		<view class="contentImg">
			<view v-for="(img,index) in evaluation.imgUrls" :key="index">
				<image :src="img" mode="widthFix" class="reviewsDetailImg"></image>
			</view>
				
					
				
		</view>
		
		
      </view>
	  
    </view>
    <!-- 底部按钮部分 -->
  <view class="fixed-container">
    <button class="reserve-btn" @click="enterBookPage(shopId)">立即预约</button>
  </view>
	
	
</view>
</template>

<script setup>
import { ref,onMounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app'
import request from '../../../utils/request';

const shopId = ref(null)
const shopInfo=ref()
const shopImg=ref([" "])
const reviewInfo=ref([])

	
	onLoad((options) => {
	  shopId.value = options.id
	  console.log('接收到的ID:', shopId.value)
	  
	  // 实际开发中这里应该请求接口获取详情数据
	  fetchShopDetail(shopId.value)
	  //刷新评论信息 
	  fetchReviewsDetail(shopId.value)
	})
	
	const fetchShopDetail = (id) => {
	  // 根据ID请求接口数据
	  request({
		  url:"/gmh/merchants/getMerchantsByMerchantId?merchantId="+id,
		  method:"get"
	  }).then(res=>{
		  // console.log(res)
		  // console.log(res[0])
		  shopInfo.value=res[0]
		  shopImg.value=res[0].storefrontImageUrl
		  // console.log(shopInfo.value)
		  // console.log(shopImg.value)
	  }).catch(err=>{
		  console.log(err)
	  })
	}
	
	const fetchReviewsDetail =(id)=>{
		
		request({
			url:"/gmh/reviews/selectReviews?userMerchantId="+id,
			method:"get"
		}).then(res=>{
			console.log(res)
			reviewInfo.value=res
			console.log(reviewInfo.value)
		}).catch(err=>{
			console.log(err)
		})
		
	}
	
	const enterBookPage = (shopId) => {
	  console.log("当前店铺ID:", shopId)
	  // 带参数跳转（小程序路径需要提前在pages.json配置）
	  uni.navigateTo({
	    url: `/pages/gmh/book_page/book_page?id=${shopId}`
	  })
	  
	}

// 店铺信息

const shopScore = '3分';
const sales = 322;

// 服务列表
const services = [
  {
    name: '小保养套餐1 (合成机油+机滤)',
    oldPrice: 299,
    newPrice: 199,
    checked: false
  },
  
];


</script>

<style>
.container {
  padding: 15px;
}

/* 轮播容器 */
.shop-swiper {
  height: 375rpx; /* 根据设计图调整高度 */
  margin-bottom: 15px;
}

/* 轮播图片样式 */
.swiper-image {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8rpx;
}

/* 指示点位置微调 */
swiper ::v-deep .wx-swiper-dot {
  bottom: 20rpx !important;
}

.shop-show {
  display: flex;
  margin-bottom: 15px;
}
.shop-show image {
  width: 100%;
  height: auto;
  max-width: 300px;
  margin-right: 15px;
}
.shop-info {
  flex: 1; /* 占据剩余空间 */
  display: flex;
  flex-direction: column; /* 垂直排列 */
  justify-content: space-between;
  width: 0; /* 防止内容溢出 */
}
.shop-name {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 5px;
}
.shop-rating {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}
.star-icon {
  width: 20px;
  height: 20px;
  margin-right: 3px;
}
.shop-score {
  margin-left: 5px;
}
.sales {
  margin-left: 10px;
}
.shop-address {
  margin-bottom: 5px;
}
.business-time {
  color: #999;
}
.section-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}
.service-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
}
.service-checkbox {
  margin-right: 10px;
}
.service-content {
  flex: 1;
}
.service-name {
  font-size: 16px;
  margin-bottom: 5px;
}
.old-price {
  text-decoration: line-through;
  color: #999;
  margin-right: 5px;
}
.new-price {
  color: red;
}
.evaluation-item {
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
}
.user-info {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}
.rating {
  margin-bottom: 5px;
}
 .rating-box {
	   	display: flex;
	   	align-items: center;
	   	margin-bottom: 15rpx;
	   }
.evaluation-content {
  margin-bottom: 5px;
}
.evaluation-images {
  display: flex;
  flex-wrap: wrap;
}
.evaluation-image {
  width: 80px;
  height: 80px;
  margin-right: 5px;
  margin-bottom: 5px;
}
.m-f{
	position: fixed;
	  width: 100%;
	  background: white;
	  z-index: 1000;
	bottom: 10px;
}
.button-section {
	height: 40px;
	width: 92vw;
	line-height: 40px;
  display: flex;
  justify-content: space-between;
}
.buy-button {
  flex: 1;
  margin-right: 10px;
  background-color: #f6390d;
  border-radius: 30px;
  color: white;
}
.confirm-button {
  flex: 1;
  background-color: #fbab07;
  border-radius: 30px;
  color: white;
}

/* 固定定位容器 */
.fixed-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  /* background: rgba(255, 255, 255, 0.1); */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 20px 0;
}

/* 主按钮样式 */
.reserve-btn {
  width: 80%;
  min-width: 280px;
  height: 88rpx;
 background: #007AFF;
  border-radius: 44rpx;
  color: #FFFFFF;
  font-size: 34rpx;
  font-weight: 500;
  line-height: 88rpx;
  text-align: center;
  transition: all 0.2s ease;
  box-shadow: 0 8rpx 24rpx rgba(0, 122, 255, 0.1);
  border: none;
}

/* 移除小程序默认样式 */
button::after {
  border: none !important;
}

/* 点击状态 */
.reserve-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
/*  box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.2); */
}
.contentImg{
	display: flex;
	flex-wrap: wrap;
	width: 100vw;
	justify-content: space-between;
}

.reviewsDetailImg{
	width: 25vw;
}



</style>